package org.alanlau.bio;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

/**
 * @author liukun
 * @version 1.0
 * @date 2020/11/10 8:46
 */
public class TimeServer {
    public static void main(String[] args) {
        int port = 8080;

        try (ServerSocket server = new ServerSocket(port)) {
            System.out.println("The time server is start in port: " + port);
            Socket socket = null;
            while (true) {
                // acceptor 阻塞在这里监听客户端的连接
                socket = server.accept();
                // 服务器新建一个线程来和客户端通信
                new Thread(new TimeServerHandler(socket)).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
